<?php
/**
 * @package Joomla
 * @subpackage Jmonoslideshow
 * @copyright (C) 2010 - Matthieu BARBE - www.ccomca.com
 * @license GNU/GPL v2
 * 
 * Jmonoslideshow is a Joomla extension for Monoslideshow.
 *
 * Jmonoslideshow uses :
 * Monoslideshow (http://www.monoslideshow.com/)
 * Plupload (http://www.plupload.com/) by Moxicode Systems
 * json class by Michal Migurski, Matt Knapp, Brett Stimmerman
 * jquery a JavaScript Library (http://jquery.com/)
 * getid3 library (http://getid3.sourceforge.net/)
 * swfobject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file (http://code.google.com/p/swfobject/)
 * Chained Selects jQuery Plugin (http://www.appelsiini.net/2010/jquery-chained-selects)
 *
 * Jmonoslideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

$doc = &JFactory::getDocument();
//load css
JHTML::stylesheet( 'jmonoslideshow.css', JMONOSLIDESHOW_MEDIA_CSS_ADMIN );
JHTML::stylesheet( 'jquery-ui.custom.css', JMONOSLIDESHOW_MEDIA_CSS_ADMIN.'Aristo/' );
JHTML::stylesheet( 'jquery.qtip.css', JMONOSLIDESHOW_MEDIA_CSS_ADMIN );
//load jquery
$doc->addScript(JMONOSLIDESHOW_MEDIA_JS_ADMIN.'jquery.min.js?version='.JMONOSLIDESHOW_JQUERY);
//load jquery ui
$doc->addScript(JMONOSLIDESHOW_MEDIA_JS_ADMIN.'jquery-ui.custom.min.js?version='.JMONOSLIDESHOW_JQUERYUI);
//load qtips
$doc->addScript(JMONOSLIDESHOW_MEDIA_JS_ADMIN.'jquery.qtip.min.js');
$host = JURI::root();
$searchTags = "
		jQuery.noConflict();
		jQuery(function() {
				function split( val ) {
					return val.split( /,\s*/ );
				}
				function extractLast( term ) {
					return split( term ).pop();
				}
						
				jQuery( '#filter_search' ).bind( 'keydown', function( event ) {
				if ( event.keyCode === jQuery.ui.keyCode.TAB &&
						jQuery( this ).data( 'autocomplete' ).menu.active ) {
					event.preventDefault();
				}
			}).autocomplete({
			source: function( request, response ) {
					jQuery.getJSON( '".$host."administrator/index.php?option=com_jmonoslideshow&task=tags.searchTags&format=json', {
						term: extractLast( request.term )
					}, response );
				},
				focus: function() {
					// prevent value inserted on focus
					return false;
				},
				search: function() {
					// custom minLength
					var term = extractLast( this.value );
					if ( term.length < 2 ) {
						return false;
					}
				},
				select: function( event, ui ) {
					var terms = split( this.value );
					// remove the current input
					terms.pop();
					// add the selected item
					terms.push( ui.item.value );
					// add placeholder to get the comma-and-space at the end
					terms.push( '' );
					this.value = terms.join( ', ' );
					return false;
				}
		});
		
		jQuery('tbody#medialisting').sortable({ handle: 'td.order',opacity: 0.6, cursor: 'move', update: function() {
		var order = jQuery(this).sortable('serialize');
		jQuery.post('".$host."administrator/index.php?option=com_jmonoslideshow&task=order.saveOrder&format=json', order, function(theResponse){
		jQuery('#contentRight').html(theResponse);
		});
		}
		});
		
		
	  jQuery('img.infomedia').each(function() // Loop over each avatar using the .each() method
   {	
		jQuery(this).qtip({
   content: {
      text: '".JText::_('COM_JMONOSLIDESHOW_LOADING')."', 
      ajax: {
         url: jQuery(this).attr('rel')
      }
   },
	  position: {
      viewport: jQuery(window)
   },
   style: {
				classes: 'ui-tooltip-wiki ui-tooltip-light ui-tooltip-shadow'
			}
});
		})
		});
						
		";
$doc = &JFactory::getDocument();									 
$doc->addScriptDeclaration($searchTags);


$listOrder	= $this->escape($this->get('list.ordering'));
$listDirn	= $this->escape($this->get('list.direction'));
?>

<form action="<?php echo JRoute::_('index.php?option=com_jmonoslideshow&view=medias'); ?>" method="post" name="adminForm" id="adminForm">
  <?php echo $this->loadTemplate('filter');?>
  <table class="adminlist">
    <thead>
      <?php echo $this->loadTemplate('head');?>
    </thead>
    <tbody id="medialisting">
      <?php echo $this->loadTemplate('body');?>
    </tbody>
    <tfoot>
      <?php echo $this->loadTemplate('foot');?>
    </tfoot>
  </table>
  <div>
    <input type="hidden" name="task" value="" />
    <input type="hidden" name="boxchecked" value="0" />
    <input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
    <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
    <?php echo JHtml::_('form.token'); ?> </div>
</form>
